arm64: add kernel config option to lock down when in Secure Boot mode
authorLinn Crosetto <linn@hpe.com>
Tue, 30 Aug 2016 17:54:38 +0000 (11:54 -0600)
committerBen Hutchings <ben@decadent.org.uk>
Mon, 17 Jul 2017 02:01:21 +0000 (03:01 +0100)
Add a kernel configuration option to lock down the kernel, to restrict
userspace's ability to modify the running kernel when UEFI Secure Boot is
enabled. Based on the x86 patch by Matthew Garrett.

Determine the state of Secure Boot in the EFI stub and pass this to the
kernel using the FDT.

Signed-off-by: Linn Crosetto <linn@hpe.com>
[bwh: Forward-ported to 4.10: adjust context]
[Lukas Wunner: Forward-ported to 4.11: drop parts applied upstream]
[bwh: Forward-ported to 4.11 and lockdown patch set:
 - Convert result of efi_get_secureboot() to a boolean
 - Use lockdown API and naming]

Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name arm64-add-kernel-config-option-to-lock-down-when.patch

arch/arm64/Kconfig
drivers/firmware/efi/arm-init.c
drivers/firmware/efi/efi.c
drivers/firmware/efi/libstub/fdt.c
include/linux/efi.h

index 3741859765cfe050d2c4a174d613ff90e1074be0..7dbe7c2fee1a856d799c581574a39b24440b3c25 100644 (file)
@@ -1033,6 +1033,18 @@ config EFI
          allow the kernel to be booted as an EFI application. This
          is only useful on systems that have UEFI firmware.
 
+config EFI_SECURE_BOOT_LOCK_DOWN
+       def_bool n
+       depends on EFI
+       prompt "Lock down the kernel when UEFI Secure Boot is enabled"
+       ---help---
+         UEFI Secure Boot provides a mechanism for ensuring that the firmware
+         will only load signed bootloaders and kernels.  Certain use cases may
+         also require that all kernel modules also be signed and that
+         userspace is prevented from directly changing the running kernel
+         image.  Say Y here to automatically lock down the kernel when a
+         system boots with UEFI Secure Boot enabled.
+
 config DMI
        bool "Enable support for SMBIOS (DMI) tables"
        depends on EFI
index 1027d7b44358d3b5806e8dcd58c65fecdcab9664..9d819a0dbbb14116fab67e943a70dad74a56db88 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/of_fdt.h>
 #include <linux/platform_device.h>
 #include <linux/screen_info.h>
+#include <linux/security.h>
 
 #include <asm/efi.h>
 
@@ -244,6 +245,11 @@ void __init efi_init(void)
             "Unexpected EFI_MEMORY_DESCRIPTOR version %ld",
              efi.memmap.desc_version);
 
+#ifdef CONFIG_EFI_SECURE_BOOT_LOCK_DOWN
+       if (params.secure_boot > 0)
+               lock_kernel_down();
+#endif
+
        if (uefi_init() < 0) {
                efi_memmap_unmap();
                return;
index b372aad3b449c39a85daa7d8df1a417741a83a73..baeb129b3051bbc4fc0e72640d80bde41db6744e 100644 (file)
@@ -613,7 +613,8 @@ static __initdata struct params fdt_params[] = {
        UEFI_PARAM("MemMap Address", "linux,uefi-mmap-start", mmap),
        UEFI_PARAM("MemMap Size", "linux,uefi-mmap-size", mmap_size),
        UEFI_PARAM("MemMap Desc. Size", "linux,uefi-mmap-desc-size", desc_size),
-       UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver)
+       UEFI_PARAM("MemMap Desc. Version", "linux,uefi-mmap-desc-ver", desc_ver),
+       UEFI_PARAM("Secure Boot Enabled", "linux,uefi-secure-boot", secure_boot)
 };
 
 static __initdata struct params xen_fdt_params[] = {
index 260c4b4b492ec38735715859522068da40c21381..52ecb8a2339cc9393841af4382509395950b0bf9 100644 (file)
@@ -134,6 +134,14 @@ static efi_status_t update_fdt(efi_system_table_t *sys_table, void *orig_fdt,
                        return efi_status;
                }
        }
+
+       fdt_val32 = cpu_to_fdt32(efi_get_secureboot(sys_table) !=
+                                efi_secureboot_mode_disabled);
+       status = fdt_setprop(fdt, node, "linux,uefi-secure-boot",
+                            &fdt_val32, sizeof(fdt_val32));
+       if (status)
+               goto fdt_set_fail;
+
        return EFI_SUCCESS;
 
 fdt_set_fail:
index 6049600e547542dbca9770bfccf1568d2ed36718..9d1e9f47708e1d0c7fd0e4d2f191f496d5299c2e 100644 (file)
@@ -736,6 +736,7 @@ struct efi_fdt_params {
        u32 mmap_size;
        u32 desc_size;
        u32 desc_ver;
+       u32 secure_boot;
 };
 
 typedef struct {